<?php

namespace App\Http\Controllers\Api;

use App\Api\Helpers\ApiResponse;
use App\Http\Controllers\Controller as BaseController;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class Controller extends BaseController
{

    use ApiResponse;
    // 其他通用的Api帮助函数

    public function __construct() {}

    /**
     * 验证参数
     *
     * @param $request
     * @param array $rule
     * @param array $message
     * @return bool|\Illuminate\Http\JsonResponse
     */
    public function validator($request, array $rule, array $message)
    {
        $validator = Validator::make($request, $rule, $message);
        if (!empty($validator->fails())) {
            $errors = $validator->errors()->toArray();
            return self::failed(array_first(array_first($errors)));
        } else {
            return true;
        }
    }
}